
//
//  BaseNavigationBar.swift
//  YiZhangGui
//
//  Created by Mac on 2020/7/23.
//  Copyright © 2020 Mac. All rights reserved.
//
//  自定义导航栏

import UIKit

class BaseNavigationBar: UIView {

    var leftBlock: (()->())?
    var rightBlock: (()->())?
    
    let leftView = UIView()
    let left = UIImageView(image: UIImage(named: "GTDC_BackArrow_Nav"))
    var navtitle: UILabel = {
        let label           = UILabel()
        label.textAlignment = .center
        label.textColor     = UIColor.white
        label.font          = UIFont.cn_fontSize(ofSize : 16.5)
        return label
    }()
    let right: UILabel = {
        let label           = UILabel()
        label.textAlignment = .right
        label.textColor     = UIColor.white
        label.font          = UIFont.cn_fontSize(ofSize: 14)
        return label
    }()
    
    
    init(target: UIViewController, title: String) {
        super.init(frame: CGRect.zero)
        self.frame = CGRect(x: 0, y: cn_statusBarHeight, width: cn_Width_Screen, height: (target.navigationController?.navigationBar.frame.height)!)
        self.backgroundColor = UIColor.clear
        
        // title
        self.navtitle.text = title
        self.addSubview(navtitle)
        navtitle.snp.makeConstraints { (m) in
            m.centerX.equalToSuperview()
            m.bottom.equalToSuperview().inset(12)
        }
        // leftView
        self.addSubview(leftView)
        leftView.cn_addTapGesture(target: self, action: #selector(self.left_Event))
        leftView.snp.makeConstraints { (m) in
            m.left.equalToSuperview()
            m.top.bottom.equalToSuperview().inset(5)
            m.width.equalTo(40)
        }
        // left
        left.cn_addTapGesture { (ges) in
            self.left_Event()
        }
        self.addSubview(left)
        left.snp.makeConstraints { (m) in
            m.left.equalTo(9)
            m.bottom.equalToSuperview().inset(12)
        }
        // right
        right.cn_addTapGesture(target: self, action: #selector(self.right_Event))
        self.addSubview(right)
        right.snp.makeConstraints { (m) in
            m.right.equalTo(-9)
            m.bottom.equalToSuperview().inset(12)
        }
        
        
    }
    // MARK: Event
    @objc private func left_Event() {
        if self.leftBlock != nil {
            self.leftBlock!()
        }
    }
    @objc private func right_Event() {
        if self.rightBlock != nil {
            self.rightBlock!()
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
